home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / tipMode.tcl < prev   
Encoding:
Text File  |  2000-12-11  |  4.9 KB  |  170 lines

  1. #################################################################################
  2. # TIP mode.
  3. # For Tcl Improvement Proposals.  As Donal Fellows says:
  4. # If you want it to be a *formal* proposal to the TCT (as opposed to just
  5. # some idea that you're floating about) then format it according to the
  6. # rules described in TIP#3:
  7. #   <http://www.cs.man.ac.uk/fellowsd-bin/TIP/3.html>
  8. # and email it to the TCT or (preferably) the acting TIP Editor
  9. # (attachments OK) at:
  10. #   <mailto:donal.fellows@cs.man.ac.uk>
  11. #================================================================================
  12. # Automatically created by mode assistant, with input from Vince.
  13. # This file is distributed under a Tcl-style free license.
  14. #
  15. # Mode: TIP
  16.  
  17.  
  18. # Mode declaration.
  19. #  first two items are: name version
  20. #  then 'source' means source this file when we first use the mode
  21. #  then we list the extensions, and any features active by default
  22. alpha::mode TIP 0.3.2 source *.tip TIPMenu {
  23.     # Script to execute at Alpha startup
  24.     addMenu TIPMenu TIP
  25. } help {
  26.     Tcl Improvement Proposals are the best of way of getting a particular
  27.     change to Tcl into the official Tcl releases.  Alpha's TIP mode
  28.     includes a TIP menu which makes it easier to write such proposals --
  29.     see the "TIP Example.tip" file for an example.
  30.  
  31.     See the TIP web page at <http://www.scriptics.com:8080/cgi-bin/tct/tip/>
  32.     for further information.
  33. }
  34.  
  35.  
  36. namespace eval TIP {}
  37.  
  38. # Mode preferences settings, which can be edited by the user (with F12)
  39.  
  40. # The email address of the current TIP editor
  41. newPref variable tipEditor donal.fellows@cs.man.ac.uk TIP
  42. # The url of the current TIP web site
  43. newPref url tipWebsite http://www.scriptics.com:8080/cgi-bin/tct/tip/ TIP
  44. # The url of the TIP formatting guidelines
  45. newPref url tipFormat http://www.scriptics.com:8080/cgi-bin/tct/tip/3.html TIP
  46. # The url of the tclcore mailing list archives
  47. newPref url tclcoreArchives "http://www.geocrawler.com/redir-sf.php3?list=tcl-core" TIP
  48.  
  49. newPref flag wordWrap 1 TIP
  50.  
  51. # These are used by the ::parseFuncs procedure when the user clicks on
  52. # the {} button in a file edited using this mode.  If you need more sophisticated
  53. # function marking, you need to add a TIP::parseFuncs proc
  54.  
  55. newPref var funcExpr {^~ [^\r\n]+} TIP
  56. newPref var parseExpr {~ (.*)} TIP
  57.  
  58. # This proc is called every time we turn the menu on.
  59. # Its main effect is to ensure this code, including the
  60. # menu definition below, has been loaded.
  61. proc TIPMenu {} {}
  62. # Now we define the menu items.
  63. Menu -n $TIPMenu -p TIP::menuProc {
  64.     createDraftTip
  65.     (-)
  66.     mailToEditor
  67.     convertToHtml
  68.     (-)
  69.     tagAsPreformatted
  70.     (-)
  71.     tipFormatting
  72.     tipWebsite
  73.     tclcoreArchive
  74. }
  75.  
  76. # This procedure is called whenever we select a menu item
  77. proc TIP::menuProc {menu item} {
  78.     global TIPmodeVars
  79.     switch -- $item {
  80.     createDraftTip {
  81.         global HOME
  82.         file::openAsTemplate [file join $HOME "Mode Examples" TIP-Example.tip]
  83.     }
  84.     mailToEditor {
  85.         set tip [getText [minPos] [maxPos -w [win::Current]]]
  86.         # Very long url's seemed to have trouble.
  87.         global tcl_platform
  88.         if {$tcl_platform(platform) == "windows"} {
  89.         if {[string length $tip] > 500} {
  90.             putScrap $tip
  91.             set tip "The TIP was placed on the clipboard (it was too long\
  92.               to handle automatically)\nJust paste it in"
  93.         }
  94.         }
  95.         url::execute [url::mailto $TIPmodeVars(tipEditor) \
  96.           body $tip subject TIP]
  97.     }
  98.     convertToHtml {
  99.         global HOME
  100.         set to "[file rootname [win::Current]].html"
  101.         script::run [file join $HOME Tools parse.tcl] -noTk $to
  102.         if {[file exists $to]} {
  103.         htmlView $to
  104.         }
  105.     }
  106.     tagAsPreformatted {
  107.         TIP::tagAsPreFormatted
  108.     }
  109.     tipFormatting {
  110.         url::execute $TIPmodeVars(tipFormat)
  111.     }
  112.     tipWebsite {
  113.         url::execute $TIPmodeVars(tipWebsite)
  114.     }
  115.     tclcoreArchive {
  116.         url::execute $TIPmodeVars(tclcoreArchives)
  117.     }
  118.     }
  119. }
  120.  
  121. # Register comment prefix
  122. set TIP::commentCharacters(General) ~
  123. # Register multiline comments
  124. set TIP::commentCharacters(Paragraph) {{~ } {~ } {~ }}
  125. # List of keywords
  126. set TIPKeyWords {
  127.     Title TIP Version Author State Type Tcl-Version Vote Created Post-History
  128. }
  129.  
  130. # Colour the keywords, comments etc.
  131. regModeKeywords -e ~ -i > -s green TIP $TIPKeyWords
  132. # Discard the list
  133. unset TIPKeyWords
  134.  
  135. newPref f autoMark 1 TIP
  136.  
  137. proc TIP::MarkFile {} {
  138.     set pos  [minPos]
  139.     set markExpr {^~ [^\r\n]+}
  140.  
  141.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $markExpr $pos} match]} {
  142.     set start [lindex $match 0]
  143.     set end   [nextLineStart $start]
  144.     regsub    {^~ } [getText $start $end] {} text
  145.     setNamedMark [string trimright $text] $start $start $start
  146.     set pos $end
  147.     }
  148. }
  149.  
  150. proc TIP::tagAsPreFormatted {} {
  151.     set sel [getSelect]
  152.     if {![string length $sel]} {
  153.     error "No current selection"
  154.     }
  155.     # Turn into spaces
  156.     set sel [text::maxSpaceForm $sel]
  157.     # split and join with leading '|'
  158.     set sel "|[join [split $sel \r\n] \r|]"
  159.     # remove a trailing | if necessary
  160.     set sel [string trimright $sel "|"]
  161.     replaceText [getPos] [selEnd] $sel
  162. }
  163.